package zhengdaoyang.settings.service.impl;

import zhengdaoyang.settings.dao.CartDao;
import zhengdaoyang.settings.dao.CartDaoImpl;
import zhengdaoyang.settings.domain.Cart;
import zhengdaoyang.settings.service.CartService;

import java.util.ArrayList;
import java.util.List;

public class CartServiceImpl implements CartService {
    private final CartDao cartDao = new CartDaoImpl();

    @Override
    public List<Cart> findallcart() {
        List<Cart> cartList = new ArrayList<Cart>();
        try {
            cartList = cartDao.findallcart();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return cartList;
    }

    public int updateCart(int num, String name) {
        int kk = 0;
        try {
            kk = cartDao.updateCart(num, name);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return kk;

    }

    @Override
    public int deleteCartGoods(String name) {

        int kk=0;
        try{
          kk= cartDao.deleteCartGoods(name);
        }catch (Exception e){
            e.printStackTrace();
        }
        return kk;
    }

    @Override
    public int deleteAllCartGoods() {
        int kk=0;
        try{
            kk= cartDao.deleteAllCartGoods();
        }catch (Exception e){
            e.printStackTrace();
        }
        return kk;
    }

    @Override
    public int insertorders(String uid,String address,String phone,String username,String omoney) {
        int kk=0;
        try{
           kk=  cartDao.insertorders(Integer.parseInt(uid),address,phone,username,Double.parseDouble(omoney));
        }catch (Exception e){
            e.printStackTrace();
        }
        return kk;
    }
}
